package com.oasys.controller;

import com.oasys.entity.dto.AllApplyInfoDto;
import com.oasys.entity.dto.ApplyDto;
import com.oasys.entity.dto.SubmitApplyDto;
import com.oasys.entity.po.ApplyTypePo;
import com.oasys.entity.po.SubmitTypePo;
import com.oasys.entity.vo.LeaveApplyVo;
import com.oasys.entity.vo.QuitVo;
import com.oasys.entity.vo.SubmitVo;
import com.oasys.enums.OaResponseCode;
import com.oasys.service.ApprovalService;
import com.oasys.utils.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 通用审批
 * @author mis_wu
 */
@Slf4j
@RequestMapping("/approval")
@RestController
public class ApprovalController {

    @Resource
    private ApprovalService approvalService;

    /**
     * 申请请假
     * @return Boolean
     */
    @PostMapping("/leaveApply")
    public ResponseResult<Boolean> leaveApply(@RequestBody LeaveApplyVo leaveApplyVo) {
        log.info("请假信息:{}",leaveApplyVo);
        return approvalService.leaveApply(leaveApplyVo);
    }

    /**
     * 获取请假类型数据
     * @return
     */
    @GetMapping("/getLeaveType")
    public ResponseResult<List<ApplyTypePo>> getLeaveType(){
        return approvalService.findApplyTypeAll();
    }

    /**
     * 查询请假数据
     * @return list
     */
    @RequestMapping("/findLeaveApplyList")
    public ResponseResult<List<ApplyDto>> findLeaveApplyList() {
        List<ApplyDto> resignApplyList = approvalService.findLeaveApplyList();
        return new ResponseResult<>(OaResponseCode.SUCCESS.getCode(),null,resignApplyList);
    }

    /**
     * 同意审批
     * @return bool
     */
    @RequestMapping("/agreeApply")
    public ResponseResult<Boolean> agreeApply(Long applyId) {
        return new ResponseResult<>(OaResponseCode.SUCCESS.getCode(),null,approvalService.agreeApply(applyId));
    }


    /**
     * 申请报销
     * @param submitVo
     * @return
     */
    @RequestMapping("/expenseSubmitApply")
    public ResponseResult<Boolean> expenseApply(SubmitVo submitVo) {
        log.info("报销参数:{}",submitVo);
        return approvalService.expenseApply(submitVo);
    }

    /**
     * 获取报销类型
     * @return
     */
    @GetMapping("/getSubmitType")
    public ResponseResult<List<SubmitTypePo>> getSubmitType(){
        return approvalService.getSubmitType();
    }

    /**
     * 查询报销数据
     * @return list
     */
    @GetMapping("/findExpenseApplyList")
    public ResponseResult<List<SubmitApplyDto>> findExpenseApplyList() {
        return approvalService.findExpenseApplyList();
    }

    /**
     * 拒绝审批
     * @return bool
     */
    @RequestMapping("/rejectApply")
    public ResponseResult<Boolean> rejectApply(Long applyId,String rejectMemo) {
        return new ResponseResult<>(OaResponseCode.SUCCESS.getCode(),null,approvalService.rejectApply(applyId,rejectMemo));
    }

    /**
     * 申请离职
     * @return Boolean
     */
    @PostMapping("/resignApply")
    public ResponseResult<Boolean> resignApply(@RequestBody QuitVo quitVo) {
        log.info("离职信息:{}",quitVo);
        return approvalService.resignApply(quitVo);
    }

    /**
     * 查询离职数据
     * @return list
     */
    @GetMapping("/findResignApplyList")
    public ResponseResult<List<ApplyDto>> findResignApplyList() {
        List<ApplyDto> resignApplyList = approvalService.findResignApplyList();
        return new ResponseResult<>(OaResponseCode.SUCCESS.getCode(),null,resignApplyList);
    }

    /**
     * 同意或拒绝离职
     * @return 上传结果及凭证Id
     */
    @RequestMapping("/approvalResignApply")
    public ResponseResult<Long> approvalResignApply() {
        return new ResponseResult<>();
    }

    /**
     * 获取所有申请信息
     * 当前管理员的
     * @return
     */
    @GetMapping("/getApplyAllInfo")
    public ResponseResult<List<AllApplyInfoDto>> getApplyAllInfo(){
        return approvalService.getApplyAllInfo();
    }
}
